package com.audi.view;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;

import com.audi.R;

public class EditTimeMinutesDialog {
	private String[] mList = { "00", "15", "30", "45" };
	private ArrayAdapter<String> mAdapterSpinner;
	private String strMinutes;
	private Button mBtnEditTimeMinutesCancel, mBtnEditTimeMinutesOk;
	private Spinner mSpnMinutes;
	private ImageButton mIbtnMinutes;
	private AudiDialog dialogTimeMinutes;
	private Context context;

	public EditTimeMinutesDialog(Context context) {
		this.context = context;
	}

	public void dialogEditTimeMinutes() {
		dialogTimeMinutes = new AudiDialog(context);
		dialogTimeMinutes.setLayout(R.layout.dialog_edit_time_minutes);
		dialogTimeMinutes.show();
		getWidget();
		addEventForWidget();

	}

	private void getWidget() {
		mBtnEditTimeMinutesCancel = (Button) dialogTimeMinutes
				.findViewById(R.id.btn_edit_minutes_cancel);
		mBtnEditTimeMinutesOk = (Button) dialogTimeMinutes
				.findViewById(R.id.btn_edit_minutes_ok);
		mSpnMinutes = (Spinner) dialogTimeMinutes
				.findViewById(R.id.spn_minutes_edit_minutes);
		mIbtnMinutes = (ImageButton) dialogTimeMinutes
				.findViewById(R.id.img_minutes_edit_minutes);

		mAdapterSpinner = new ArrayAdapter<String>(context,
				android.R.layout.simple_spinner_item, mList);
		mAdapterSpinner
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mSpnMinutes.setAdapter(mAdapterSpinner);
	}

	private void addEventForWidget() {
		mIbtnMinutes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				mSpnMinutes.performClick();
				mSpnMinutes
						.setOnItemSelectedListener(new OnItemSelectedListener() {

							@Override
							public void onItemSelected(AdapterView<?> arg0,
									View arg1, int arg2, long arg3) {
								strMinutes = mList[arg2];
							}

							@Override
							public void onNothingSelected(AdapterView<?> arg0) {
								strMinutes = "";
							}
						});
			}
		});
		mBtnEditTimeMinutesCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(context, "Back about 5-3-3-1",
						Toast.LENGTH_SHORT).show();
				dialogTimeMinutes.dismiss();
			}
		});
		mBtnEditTimeMinutesOk.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(context,
						"Continue 5-3-2-5: " + "Minutes - " + strMinutes,
						Toast.LENGTH_LONG).show();
				dialogTimeMinutes.dismiss();
			}
		});
	}
}
